package tn.insat.gl4.ppp;

import greendroid.app.GDActivity;
import greendroid.widget.QuickAction;
import greendroid.widget.QuickActionBar;
import greendroid.widget.QuickActionWidget;
import greendroid.widget.QuickActionWidget.OnQuickActionClickListener;

import java.util.ArrayList;
import java.util.HashMap;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class InfoOfDevelopers extends GDActivity {
	private ListView maListViewPerso;
	private QuickActionWidget quickActions;
	private int IdDeveloper;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setActionBarContentView(R.layout.infodeveloppers);
		initQuickActionBar();

		maListViewPerso = (ListView) findViewById(R.id.listdevelopers);
		ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();

		addItemToList("Houcine Gasmi", "Developer", R.drawable.ic_launcher,
				listItem);
		addItemToList("Rabie Derouich", "Developer", R.drawable.ic_launcher,
				listItem);
		addItemToList("Toumi Abdennour", "Developer", R.drawable.ic_launcher,
				listItem);
		addItemToList("Moussi Aymen", "Developer", R.drawable.ic_launcher,
				listItem);
		addItemToList("Yassine Jaouane", "Developer", R.drawable.ic_launcher,
				listItem);

		SimpleAdapter mSchedule = new SimpleAdapter(this.getBaseContext(),
				listItem, R.layout.infodeveloper, new String[] { "img", "name",
						"info" }, new int[] { R.id.img, R.id.name, R.id.info });

		maListViewPerso.setAdapter(mSchedule);

		maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
			@SuppressWarnings("unchecked")
			public void onItemClick(AdapterView<?> a, View v, int position,
					long id) {
				// // on récupère la HashMap contenant les infos de notre item
				// // (name, info, img)
				// HashMap<String, String> map = (HashMap<String, String>)
				// maListViewPerso
				// .getItemAtPosition(position);
				// // on créer une boite de dialogue
				// AlertDialog.Builder adb = new AlertDialog.Builder(
				// InfoOfDevelopers.this);
				// // on attribut un name à notre boite de dialogue
				// adb.setTitle("Sélection Item");
				// // on insère un message à notre boite de dialogue, et ici on
				// // affiche le name de l'item cliqué
				// adb.setMessage("Votre choix : " + map.get("name"));
				// // on indique que l'on veut le bouton ok à notre boite de
				// // dialogue
				// adb.setPositiveButton("Ok", null);
				// // on affiche la boite de dialogue
				// adb.show();
				IdDeveloper = position;
				quickActions.show(v);
			}
		});

	}

	private void addItemToList(String name, String info, int icLauncher,
			ArrayList<HashMap<String, String>> listItem) {
		HashMap<String, String> map;
		map = new HashMap<String, String>();
		map.put("name", name);
		map.put("info", info);
		map.put("img", String.valueOf(icLauncher));
		listItem.add(map);
	}

	private void initQuickActionBar() {
		quickActions = new QuickActionBar(this);
		quickActions.addQuickAction(new QuickAction(this, R.drawable.facebook,
				"Facebook"));
		quickActions.addQuickAction(new QuickAction(this, R.drawable.twitter,
				"Twitter"));
		quickActions.addQuickAction(new QuickAction(this, R.drawable.mail,
				"Email"));
		quickActions
				.setOnQuickActionClickListener(new OnQuickActionClickListener() {
					public void onQuickActionClicked(QuickActionWidget widget,
							int position) {
						Toast.makeText(InfoOfDevelopers.this,
								"Item " + position + " clicked",
								Toast.LENGTH_SHORT).show();
						switch (IdDeveloper) {
						case 0: // TODO click on developer 0 do not forget switch position
							break;
						case 1: // TODO click on developer 1 do not forget switch position
							break;
						case 2: // TODO click on developer 2 do not forget switch position
							break;
						case 3: // TODO click on developer 3 do not forget switch position
							break;
						case 4: // TODO click on developer 4 do not forget switch position
							break;
						default:
							break;
						}
					}
				});
	}

}
